//
// Created by tang on 23-4-1.
//

#ifndef PIINFO_UI_STYLE_HPP
#define PIINFO_UI_STYLE_HPP

#include "imgui.h"
#include <unordered_map>
#include <xml/pugixml.hpp>

enum class style_mode {
    none,
    self_only,
    with_child,
};

class  ui_style { // style color, style var
public:
    void use() const;

    void revert(style_mode mode) const;

    static ui_style* create_from_node(const pugi::xml_node& node);

private:
    bool init(const pugi::xml_node& node);

    bool append_style(const std::string& k, const std::string& v, bool self_only);

    struct var_value {
        bool is_float;
        union {
            float  f_value;
            ImVec2 v2_value;
        };
    };
    
    std::unordered_map<ImGuiStyleVar, var_value> vars_all;
    std::unordered_map<ImGuiStyleVar, var_value> vars_self;
    std::unordered_map<ImGuiCol, ImVec4>         colors_all;
    std::unordered_map<ImGuiCol, ImVec4>         colors_self;
};

enum class option_mode {
    none,
    temporary,      // using SetNextItemXXX
    persistence,    // using PushItemXXX
};

class ui_options {
public:
    void use();

    void revert();

    static ui_options* create_from_node(const pugi::xml_node& node);

private:
    bool init(const pugi::xml_node& node);

    float style_width{};
};

#endif  // PIINFO_UI_STYLE_HPP
